<%@page import="org.hibernate.envers.entities.mapper.relation.lazy.initializor.ListCollectionInitializor"%>
<%@ page import="cardbs.domain.Employee"%>
<%@ page import="cardbs.domain.Department"%>
<%@ page import="cardbs.domain.Part"%>
<%@ page import="java.util.*"%>
<%@ page import="cardbs.dao.*"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Διαγραφή Ανταλλακτικών</title>
<script language="JavaScript" type="text/javascript">
function checkform (updateForm)
{
var sum = updateForm.sum.value;

for(var i = 0; i < sum; i++){	
	
	if(document.getElementById('select'+i).checked) {
	
			return true;
		}
			

}
alert ("Παρακαλώ επιλέξτε τα ανταλλακτικά που θέλετε να διαγράψετε!" );
return false;
}
  </script>
</head>
<body>
<%
Employee employee = (Employee)session.getAttribute("Administrator");
//HashSet <Department> departments = (HashSet)session.getAttribute("depList");
HashSet <Part> parts = (HashSet)session.getAttribute("allParts");
%>
	<div align="center">
	<jsp:include page="exitPage.jsp"/>
<form method="post" name="updateForm" action="/car-dbs-implementation/DeletePartInfoservlet" onsubmit="return checkform(this);">
		
<table><tr><td>Κωδικός ανταλλακτικού</td><td>Περιγραφή</td><td>Κατασκευαστής</td><td>Έτος Κατασκευής</td><td>Τιμή</td><td>Επιλογή</td></tr>			
<% 
int i=0;
try {
for (Part part: parts){
%>
<tr><td><%= part.getPartCode()%></td>
<td><input name="name<%=i%>" value="<%= part.getPartName()%>" size="15" /></td>
<td><input name="company<%=i%>" value="<%= part.getCompany()%>" size="15" /></td>
<td><input name="year<%=i%>" value="<%= part.getManufacturyYear()%>" size="15" /></td>
<td><input name="price<%=i%>" value="<%= part.getPrice()%>" size="15" /></td>
<td><input type="checkbox" id = "select<%=i%>" name="select<%=i%>" /></td></tr>
<input type="hidden" name="part<%=i%>" value="<%=part.getPartCode() %>" />
<%
i++;
}
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

%>
<input type="hidden" value="<%=i %>" name="sum" />
<tr><td colspan="2"><input TYPE="submit" VALUE="Διαγραφή" name="enimerosi" style="width: 193px" /></td>
<td><a href="/car-dbs-implementation/uipages/firstPagePages/AdministratorViewLoginPage.jsp"><img src="../../images/CancelButton.png" style="border:1px solid black;"/></a></td></tr>		
		
		</table>		
		</form>
	<%
		String error3 = (String)session.getAttribute("partInUse");
		
		if ((error3!=null) && (error3.equals("true")))
		{
		%>
		<p><font size="4" face="arial" color="red">Αδύνατη η διαγραφή του ανταλλακτικού - Το ανταλλακτικό χρησιμοποιείται !!!</p><%
		
		session.setAttribute("partInUse","false");}%>		
	</div>

</body>
</html>